package com.lzq.chatroom_project.common.pojo;

public class Result<T> {
    //状态码
    private int code;
    //描述信息
    private String message;
    //具体的数据
    private T data;

    /**
     * 构造方法
     * @param code
     * @param message
     */
    public Result(int code, String message) {
        this(code,message,null);
    }

    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 成功
     * @return
     */
    public static Result success() {
        return new Result(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage());
    }

//    public static Result success(String switchKey) {
//        return new Result(ResultCode.SUCCESS.getCode(),switchKey);
//    }

    public static <T> Result<T> success(T data) {
        return new Result(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage(),data);
    }

    public static <T> Result<T> success(String message, T data) {
        return new Result(ResultCode.SUCCESS.getCode(),message,data);
    }

    /**
     * 失败
     * @return
     */
    public static Result failed() {
        return new Result(ResultCode.FAILED.getCode(),ResultCode.FAILED.getMessage());
    }

    public static Result failed(String message) {
        return new Result(ResultCode.FAILED.getCode(),message);
    }

    public static Result failed(ResultCode resultCode) {
        return new Result(resultCode.getCode(),resultCode.getMessage());
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", switchKey='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
